package com.rongji.dfish.demo.index.service;

import java.util.Collections;
import java.util.List;

import org.springframework.stereotype.Service;

import com.rongji.dfish.demo.editor.service.CommonService;
import com.rongji.dfish.demo.entity.DfishViewNode;
import com.rongji.dfish.framework.service.BaseService;

@Service
public class DemoService extends BaseService<DfishViewNode, String>{

	public void saveViewNode(DfishViewNode dViewNode) {
		if (dViewNode == null) {
			return;
		}
		dViewNode.setNodeId(CommonService.getNewId());
		pubCommonDAO.save(dViewNode);
	}

	public void updateViewNode(DfishViewNode dViewNode) {
		if (dViewNode == null) {
			return;
		}
		pubCommonDAO.update(dViewNode);
	}

	public void deleteViewNode(String nodeId) {
		pubCommonDAO.bulkUpdate("DELETE FROM DfishViewNode t WHERE t.nodeId=?", nodeId);
	}

	public DfishViewNode getViewNode(String nodeId) {
        DfishViewNode result = (DfishViewNode) pubCommonDAO.queryAsAnObject("FROM DfishViewNode t WHERE t.nodeId=?", nodeId);
		return result;
	}

	public List<DfishViewNode> findViewNodes(String viewId) {
		@SuppressWarnings("unchecked")
        List<DfishViewNode> result = (List<DfishViewNode>) pubCommonDAO.getQueryList("FROM DfishViewNode t WHERE t.viewId=?", viewId);
		if (result == null) {
			return Collections.emptyList();
		}
		return result;
	}


	
}
